// /import core
// /import commands\inserthtml.js
// /commands 分割线
/**
 * 分割线
 * 
 * @function
 * @name baidu.editor.execCommand
 * @param {String}
 *            cmdName horizontal插入分割线
 */
(function() {
	var domUtils = baidu.editor.dom.domUtils;
	baidu.editor.commands['horizontal'] = {
		execCommand : function(cmdName) {
			if (this.queryCommandState(cmdName) !== -1) {
				this.execCommand('insertHtml', '<hr>');
				var range = this.selection.getRange(), start = range.startContainer;
				if (start.nodeType == 1 && !start.childNodes[range.startOffset]) {

					var tmp;
					if (tmp = start.childNodes[range.startOffset - 1]) {
						if (tmp.nodeType == 1 && tmp.tagName == 'HR') {
							if (this.options.enterTag == 'p') {
								tmp = this.document.createElement('p');
								range.insertNode(tmp);
								range.setStart(tmp, 0).setCursor();

							} else {
								tmp = this.document.createElement('br');
								range.insertNode(tmp);
								range.setStartBefore(tmp).setCursor();
							}
						}
					}

				}
				return true;
			}

		},
		// 边界在table里不能加分隔线
		queryCommandState : function() {
			if (this.highlight) {
				return -1;
			}
			var range = this.selection.getRange();
			return domUtils.findParentByTagName(range.startContainer, 'table')
					|| domUtils
							.findParentByTagName(range.endContainer, 'table')
					? -1
					: 0;
		}
	};
})();
